{include file="common/header"}
<link href="/static/admin/css/other.css" rel="stylesheet">
<main class="lyear-layout-content">
    <div class="container-fluid">
        <div class="row ant-menu-submenu">
            <div class="col-lg-10 col-b90">
                <div class="card">
                    <div class="right-card-header card-header">
                        <h4>{:lang('set.evalu_set')}</h4>
                    </div>
                    <div class="card-body">
                        <div class="example-box set_evaluation">
                            <div class="form-group row">
                                <div class="col-xs-3">{:lang('set.evalu_inst')}</div>
                                <div class="col-xs-4">
                                    <input class="form-control" type="text" id="evins-text" value="{$evalu['evins']}">
                                </div>
                            </div>
                            <div class="form-group row xing">
                                <div class="col-xs-3">{:lang('set.evalu_entry')}</div>
                                <div class="col-xs-2">
                                {if !empty($evalu['evlimit'][0])}
                                    <input class="form-control" type="text" value="{$evalu['evlimit'][0]}">
                                {/if}
                                </div>
                                <div class="col-xs-2 xingxing-list">
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                </div>
                            </div>
                            {if !empty($evalu['evlimit'])}
                            {foreach $evalu['evlimit'] as $key=>$item}
                            {if $key >= 1}
                            <div class="form-group row xing">
                                <div class="col-xs-3"></div>
                                <div class="col-xs-2">
                                    <input class="form-control" type="text" value="{$item}">
                                </div>
                                <div class="col-xs-2 xingxing-list">
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                    <i class="iconfont icon-xingxing_selected"></i>
                                </div>
                                <div class="col-xs-1 iconfont-delete">
                                    <i class="iconfont icon-delete pointer"></i>
                                </div>
                            </div>
                            {/if}
                            {/foreach}
                            {/if}
                            <div class="form-group row">
                                <div class="col-xs-3"></div>
                                <div class="col-xs-2">
                                    <button class="btn btn-label btn-primary" id="add-action-eval-temp">
                                        <label>
                                            <i class="iconfont icon-plus-line"></i>
                                        </label>{:lang('set.add_line')}
                                    </button>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-xs-3">{:lang('set.writing_evalu')}</div>
                                <div class="col-xs-2">
                                    <label class="lyear-switch switch-success">
                                        <input{:checked($evalu['wzev_open'], 1)} type="checkbox" id="evins-wzev_open">
                                        <span></span>
                                    </label>
                                </div>
                            </div>
                            <div class="wzpj form-group row{if $evalu['wzev_open'] == 0} hide{/if}">
                                <div class="col-xs-3">{:lang('set.writing_evalu_name')}</div>
                                <div class="col-xs-3">
                                    <input class="form-control" type="text" id="evins-wzev_name" value="{$evalu['wzev_name']}">
                                </div>
                            </div>
                            <div class="form-group col-md-12 mt-50">
                                <input type="hidden" id="evins-id" value="{$evalu['id']}">
                                <button type="submit" class="btn btn-default" id="add-set-evaluation">{:lang('public.determine')}</button>
                                <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">{:lang('public.return')}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
{include file="common/footer"}
<script>
    let IM_config = {
        addEvaluation: "{:adminUrl('admin/Set/set_evaluation')}",
    };

    $(function () {
        /**
         * 增加条目模板
         */
        $('#add-action-eval-temp').click(function () {
            if ($(".xing").length > 4) {
                return we_im_msg('最多5个');
            }
            var temp = '<div class="form-group row xing">'+
                '<div class="col-xs-3"></div>'+
                '<div class="col-xs-2">'+
                    '<input class="form-control" type="text">'+
                '</div>'+
                '<div class="col-xs-2 xingxing-list">'+
                    '<i class="iconfont icon-xingxing_selected"></i>'+
                    '<i class="iconfont icon-xingxing_selected"></i>'+
                    '<i class="iconfont icon-xingxing_selected"></i>'+
                    '<i class="iconfont icon-xingxing_selected"></i>'+
                    '<i class="iconfont icon-xingxing_selected"></i>'+
                '</div>'+
                '<div class="col-xs-1 iconfont-delete">'+
                    '<i class="iconfont icon-delete pointer"></i>'+
                '</div>'+
            '</div>';
            $('.xing:last').after(temp);
        });

        /**
         * 删除条目
         */
        $('body').on('click','.xing .iconfont-delete', function() {
            $(this).parents('.xing').remove();
        });

        /**
         * 显示评论文字
         */
        $('#evins-wzev_open').click(function() {
            if (!$('#evins-wzev_open:checked').val()) {
                $('.wzpj').addClass('hide');
            } else {
                $('.wzpj').removeClass('hide');
            }
        });

        /**
         * 提交
         */
        $('#add-set-evaluation').click(function () {
            var evlimit = [];
            $.each($('.xing input'),function(index, item) {
                if ($(item).val() != '') {
                    evlimit.push($(item).val());
                }
            });
            var data = {
                evins_id: $('#evins-id').val(),
                evins: $('#evins-text').val(),
                evlimit: evlimit.join(),
                wzev_open: $('#evins-wzev_open:checked').val()=='on'?1:0,
                wzev_name: $('#evins-wzev_name').val()
            };
            $.ajax({
                type: "post",
                url: IM_config.addEvaluation,
                data: data,
                dataType: "json",
                success : function(r) {
                    we_im_msg(r.data);
                    setTimeout(function() {
                        location.reload();
                    },2000);
                }
            });
        });
    });
</script>
<script type="text/javascript" src="/static/admin/js/set.js"></script>